// 云函数入口文件
const cloud = require('wx-server-sdk')

 //云开发环境初始化
 cloud.init({
  env: 'cloud1-7g1a0u3je2bf6f8d', //所对应的环境ID
  traceUser: true
})


exports.main = async(event, context) => {
  try {
    const result = await cloud.openapi.subscribeMessage.send({
      touser: event.openid, //要推送给那个用户
      page: 'pages/get/get', //要跳转到那个小程序页面
      data: {//推送的内容
        character_string19: {  // 订单编号
          value: event.orderID
        },
        name13: {  // 接单人
          value: event.name
        },
        phrase14: {   // 订单状态
          value: '已被接单'
        },
        phone_number15: {  // 联系电话
          value: event.phoneNumber
        },
        time4: {  // 接单时间 
          value: event.time
        },
      },
      templateId: '6TvIGy7QzeVGqZJCySdrfjmMOpNvGktM0j_A2PEVSxQ' //模板id
    })
    //console.log(result)
    //return result
    return result.errCode
  } catch (err) {
    console.log(err)
    return err
  }
}
